package service

import (
	"e_mall_server/dao/mysql"
	"e_mall_server/models"
)

/**
 * @Author: zhaobin
 * @Description TODO
 * @Date: 2022-05-19 22:33
 */

// GetAddressList 获取收获地址列表接口
func GetAddressList(userId int64) ([]models.Address, error) {
	return mysql.GetAddressList(userId)
}

// AddAddress 添加收获地址信息
func AddAddress(address *models.Address) error {
	//// 更新当前用户的所有收货地址的默认收货地址状态为0
	//if err := mysql.UpdateDefaultAddressByUserId(address.UserId); err != nil {
	//	return err
	//}
	//// 增加当前收货地址，让默认收货地址状态是1
	//address.DefaultAddress = 1
	return mysql.AddAddress(address)
}

// UpdateAddress 修改收获地址信息
func UpdateAddress(address *models.Address) int64 {
	return mysql.UpdateAddress(address)
}

// DeleteAddressById 通过收获地址id删除收获地址数据
func DeleteAddressById(id int64) int64 {
	return mysql.DeleteAddressById(id)
}

// GetAddressDetailById 通过收获地址id获取收获地址详细信息
func GetAddressDetailById(id int64) (models.Address, error) {
	return mysql.GetAddressDetailById(id)
}
